<template>
	<!-- 获取验证码页面 -->
	<view class="content flex-column flex-aligin-items-center">
		<view class="user-text">
			<text class="user-bgcolor fun-font-14px" name="warrantytext">{{usertext}}</text>
		</view>
		<view class="phone flex-row">
			<view class="phone-left flex-row">
				<view class="phone-text">
					<text class="fun-font-14px">{{phonego}}</text>
				</view>
				<view class="phone-right flex-row-reverse">
					<image src="../../../static/img/go.svg" class="fun-img"></image>
				</view>	
			</view>	
			<view class="phone-input">
				<input type="number" placeholder="请输入手机号" v-model.trim="rule.mobile" maxlength="11">
				<text v-if="!isShow" class="fun-font-10px">{{realphone}}</text>
		     </view>
		</view>
		<view class="verify-box  flex-center flex-row">
			<view class="verify-input fun-font-14px" >
				<input placeholder="请输入短信验证码" v-model="rule.verify" type="number"/>
			</view>
			<view class="prepare fun-font-12px">
				<!-- <view @click="getCode"  class=""></view> -->
				<button v-show="isgetCode" class="btn-color fun-font-12px" plain="flase" @click="textsend(rule)">获取验证码</button>
				<view v-show="!isgetCode"  v-bind:class="{active:isActive}" class="bt-prepare ">
				<text v-show="isActive" @click="textsend(rule)">重新获取</text>
				<text v-show="!isActive" style="color: #888888;">{{count}}s后重新获取</text>
				</view>
			</view>
			
		</view>
		<view class="confirm">
			<view class="confirm-view">
				<button @click="confirm"  class="fun-img phonebtn-color fun-font-16px flex-center">{{confirmtext}}</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				usertext: '联系人',
				rule:{
					mobile: '',
					verify:'',
				},
				isgetCode:true,
				isActive:false,
				count:0,
				timer:null,
				phonego:' +86',
				isShow: true,
				realphone:'手机号错误',	
				confirmtext:'确定',
				name:''
			}
		},
		onLoad(option) {
			console.log(option)
		    this.name = option.name
			console.log(this.name)
			
		},
		methods: {
			/**
			 * 获取验证码
			 */
			requestCod(){
				uni.request({
				    url: 'http://localhost/repair/index.php/evaluate_user',
				    data: {
				        user_phone: this.rule.mobile,
						action:"sendCode"
				    },
					method: "POST",
				    header: {
						'content-type':'application/json'
				       //自定义请求头信息
				    },
				    success: (res) => {
				       if(res.code===1){
						   console.log(res.msg)
						   this.rule.verify=res.result.code
					   }	
				    },
					fail: (err)=>{
						console.log(err)
					}
				});
			},
			/* 倒计时 */
			textsend(rule) {
				this.requestCod();
				this.isgetCode=false;
				if(!this.timer){
					this.count = 60;
					this.isActive = false;
					this.timer = setInterval(() =>{
						if(this.count > 0 && this.count <=60){
							this.count--;
						}else{
							this.isActive = true;
							clearInterval(this.timer);
							this.timer = null;
						}
					},1000);
				  }
				},
			
			confirm(){
				let loginRules = [
				  {name: 'mobile', required: true, type: 'phone', errmsg: '请输入正确的手机号'},
				  {name: 'verify', type: 'required', errmsg: '请输入验证码'},
				  {name: 'verify', type: 'lengthRange', min: 6, max: 6, errmsg: '请正确输入验证码'}
				]
				let valLoginRes = this.$validate.validate(this.rule, loginRules) 
				 if (!valLoginRes.isOk) {
				  uni.showToast({
				    icon: 'none',
				    title: valLoginRes.errmsg
				  });
				}else{
					uni.reLaunch({
						url:'../maintain/maintain'
					});
				}
				/* let keyless = this.name
				if(keyless === 'repair'){
					  uni.navigateTo({
					  	url:'../repair/repair?name=repair'
					  })
				}else if(keyless === 'complainrouter'){
					  uni.navigateTo({
					  	url:'../advise/complain?name=wcomplain'
					  })
				}else if(keyless ==='adviserouter'){
					  uni.navigateTo({
					  	url:'../advise/advise?name=wadvise'
					  })
				}
				 */
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		/* height: 1240rpx; */
		height: 100%;
		background-color: #efeff4;

		.user-text {
			width: 100%;
			height: 90rpx;
			background-color: #FFFFFF;
            border-bottom: 4rpx solid #EFEFF4;
			.user-bgcolor {
				width: 100%;
				height: 80rpx;
				display: flex;
				text-indent: 10rpx;
                flex-direction: column-reverse;
			}
		}
		.phone{
			width: 100%;
			height: 100rpx;
			background-color: #FFFFFF;
			border-bottom: 4rpx solid #FFFFFF;
				.phone-left{
					width: 20%;
					height: 100rpx;
					border-right: 4rpx solid #efeff4;
					text-align: center;
					margin-left: 20rpx;
					margin-right: 20rpx;
					.phone-text{
						width:40%;
						height: 100rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						
					}
					.phone-right{
				    margin-left: 40rpx;
					width: 30rpx;
					height: 30rpx;
						}
				.phone-input{
					width: 80%;
					height: 100rpx;
					text-align: center;
					
				}
			}
			
		}
	    .verify-box{
			width: 100%;
			height: 100rpx;
			background-color: #FFFFFF;
			border-top: 4rpx solid #efeff4;
			border-bottom: 4rpx solid #efeff4;
			.verify-input{
				width: 70%;
				height: 100rpx;
				text-align: center;
				display: flex;
				flex-direction: row;
				align-items: center;
				border-right: 4rpx solid #efeff4;
			}
			.prepare{
				width: 30%;
				height: 100rpx;
				display: flex;
				color: #1aa034;
				line-height: 28rpx;
				flex-direction: row;
				align-items: center;
				justify-content: center;
				align-content: center;
				.btn-color{
					border: 0 solid #FFFFFF;
					color: #dbdbde;
					background-color: #FFFFFF;
					font-size: 28rpx;
				}
				.bt-prepare{
					color: #000000;
					background-color: #FFF;
					line-height: 28rpx;
					font-size: 28rpx;
					text-align: center;
				}
				.active{
					color: #55aaff;
					background-color: #FFFFFF;
				}
			}
			
		}
		.confirm{
			margin-top: 20rpx;
			width: 90%;
			height: 90rpx;
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			.confirm-view{
				width: 100%;
				height: 90rpx;
				text-align: center;
				background-color: #efeff4;
				.phonebtn-color{
					background-color: #3CC51F;
					color: #FFFFFF;
				}
			}
		}	
	}
</style>
